package classes.view
{
	import classes.OX_Application;
	import classes.controller.DAOSendFlash;
	import classes.controller.EClick;
	import classes.controller.EDataObject;
	import classes.view.component.ListRoom;
	
	import flash.events.Event;
	import flash.external.ExternalInterface;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class Mediator_ListRoom extends Mediator implements IMediator
	{
		public static const NAME:String = "Mediator_ListRoom";
		public function Mediator_ListRoom(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			init();
		}
		
		override public function listNotificationInterests():Array
		{
			return [OX_Application.THE_FIRST_EXECUTE,
					OX_Application.APPLICATION_EXECUTE,
					OX_Application.LIST_ROOM_ON,
					OX_Application.LIST_ROOM_OFF
					
			];
		}
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName()){
				case OX_Application.THE_FIRST_EXECUTE :
					sendNotification(OX_Application.LOADING_IN);
					listRoom.listroom_switch 	= true;
					break;
				case OX_Application.APPLICATION_EXECUTE :
					sendNotification(OX_Application.LOADING_IN);
					listRoom.listroom_switch 	= true;
					break;
				case OX_Application.LIST_ROOM_OFF :
					listRoom.listroom_switch 	= false;
				break;
				case OX_Application.LIST_ROOM_ON :
					listRoom.listroom_switch	= true;
				break;
			}
		}
		
		private function init():void
		{
			listRoom.addEventListener(EClick.EVENT_CLICK,					sendBtnDispatch);
			listRoom.addEventListener(EDataObject.EVENT_DATAOBJECT,			sendJoinRoomDispatch);
			listRoom.addEventListener("loadingOff",							loadingOffSend);
		}
		
		private function sendBtnDispatch(e:EClick):void
		{
			//방만들기, 바로가기, 싱글모드.
			sendNotification(OX_Application.CLICK_EVENT, e._click);
		}
		
		private function sendJoinRoomDispatch(e:EDataObject):void
		{
			//joinRoom.
			sendNotification(OX_Application.WAITING_ROOM_IN);
		}
		
		private function loadingOffSend(e:Event):void{sendNotification(OX_Application.LOADING_OUT);}
		
		
		protected function get listRoom():ListRoom
		{
			return viewComponent as ListRoom;
		}
	}
}
